package com.example.demo.day0226;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Test {
        public static void main(String[] args) {
            Person p1 = new Person(14,"A");
            Person p2 = new Person(12,"B");
            Person p3 = new Person(13,"C");
            Person p4 = new Person(11,"D");
            List<Person> people = new ArrayList<Person>();//将person的元素放进一个list集合
            people.add(p1);
            people.add(p2);
            people.add(p3);
            people.add(p4);

            Person ps=Collections.max(people,new Person());////根据重写的comparator方法返回集合中的最大元素
            System.out.println(ps.name + "."+ps.age);

            Person pr=Collections.min(people,new Person());////根据重写的comparator方法返回集合中的最小元素
            System.out.println(pr.name + "."+pr.age);
//
//            for (Person p : people){//使用foreach遍历list集合
//                System.out.println(p.name + "."+p.age);
//            }
//            Collections.sort(people,new Person());//根据指定的Comparator方法产生的顺序对集合元素进行排序
//            System.out.println("------------------");
//            for (Person pe:people){
//                System.out.println(pe.name + ","+pe.age);
//            }
        }
}
